package chapter09.h9_2;

import chapter09.h9_1.DisplayImpl;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileDisplayImpl extends DisplayImpl {
    private String filename;
    private BufferedReader bf;

    public FileDisplayImpl(String filename, BufferedReader bf) {
        this.filename = filename;
    }

    @Override
    public void rawOpen() {
        try {
            bf = new BufferedReader(new FileReader(filename));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("=========="+filename+"==========");
    }

    @Override
    public void rawPrint() {
        try {
            String line;
            while ((line = bf.readLine())!=null){
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void rawClose() {
        System.out.println("====================");
        try {
            bf.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
